rows = 'ABCDEFGHI'
cols = '123456789'

def vanilla():
    board = "<table border=1>\n"
    for r in rows:
        board += "<tr>\n"
        for c in cols:
            board += "<td>{{ values.%s%s }}</td>" % (r, c) + "\n"
        board += "</tr>\n"
    board += "</table>\n"
    return board

def final():
    def sub(riv, civ):
        ri = rows.find(riv)
        ci = cols.find(civ)
        board = "<table border=1>\n"
        for r in rows[ri:ri+3]:
            board += "<tr>\n"
            for c in cols[ci:ci+3]:
                board += "<td>{{ values.%s%s }}</td>" % (r, c) + "\n"
            board += "</tr>\n"
        board += "</table>\n"
        return board

    board = "<table border=1>\n"
    for r in rows[::3]:
        board += "<tr>\n"
        for c in cols[::3]:
            board += "<td>\n%s</td>\n" % sub(r, c)
        board += "</tr>\n"
    board += "</table>\n"
    return board

def write(name, board):
    open('board_%s.html' % name, 'w').write(board)

write('vanilla', vanilla())
write('final', final())
